package ControlLayer;
import java.util.ArrayList;
import ModelLayer.Person;
import ModelLayer.AddressBook;
//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author Gruppe A 
 * @version 1.0
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
    private AddressBook ab;
    
    
    /**
     * Constructor for the controller.
     */
    public AddressCtr()
    {
        ab = AddressBook.getInstance();
    }
    
    //Dummy implementation: after implementing the model layer 
    //objects of class Person are to be returned, not String
    /**
     * An accessor method for finding a person. it executes the command from our container for Persons(addressbook)
     * @param long id
     * @return Person person
     */
    public Person getPerson(long id)
    {
        //this method is to search the container for a person
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer
        return ab.findPerson(id);
    }
    
    /**
     * A method for creating new objects of Person takes a variety of parameters
     * it also takes the newly created object and stores it in our container for Persons(addressbook)
     * @param long id
     * @param String name
     * @param String address
     * @param int postnr
     * @param String city
     * @param String phoneNumber
     */
    public void createPerson(long id, String name, String address, int postnr, String city, String phone)
    {   
      Person p = new Person(id, name, address, postnr, city, phone);
      ab.addPerson(p);
    }
    
    /**
     * A method for deleting objects of Person from the ArrayList in our container for Persons(addressbook)
     * @param long id
     */
    public void deletePerson(long id)
    {
        Person p = ab.findPerson(id);
        ab.removePerson(p);
    }
    
    /**
     * A method for updating a person, it executes the command found in our container for Persons(addressbook)
     * @param long id
     * @param String name
     * @param String address
     * @param int postnr
     * @param String city
     * @param String phoneNumber 
     */
    public void updatePerson(long id, String name, String address, int postnr, String city, String phoneNumber)
    {
        ab.updatePerson(id, name, address, postnr, city, phoneNumber);
    }
    
    /**
     * A method for listing all the people in our address book, it executes
     * the command found in our container Persons(addressbook)
     * @return ArrayList myPersons
     */
    public ArrayList listAllPersons()
    {
        
          return ab.listPersons();
    }
}
